﻿using System;
using System.Windows.Markup;

namespace ChessKit.Common
{
  public class BoardLocationExtension : MarkupExtension
  {
    public BoardArea Area { get; set; }

    public BoardLocationExtension()
    {
      Area = BoardArea.Unknown;
    }

    public BoardLocationExtension(BoardArea boardArea)
    {
      switch (boardArea)
      {
        case BoardArea.Background:
        case BoardArea.TopLeftCorner:
        case BoardArea.TopRightCorner:
        case BoardArea.BottomLeftCorner:
        case BoardArea.BottomRightCorner:
        case BoardArea.Unknown:
          Area = boardArea;
          break;
        default:
          throw new ArgumentException("boardArea");
      }
    }

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
      switch (Area)
      {
        case BoardArea.Background: return BoardLocation.Background;
        case BoardArea.TopLeftCorner: return BoardLocation.TopLeftCorner;
        case BoardArea.TopRightCorner: return BoardLocation.TopRightCorner;
        case BoardArea.BottomLeftCorner: return BoardLocation.BottomLeftCorner;
        case BoardArea.BottomRightCorner: return BoardLocation.BottomRightCorner;
        case BoardArea.Unknown: return BoardLocation.Unknown;
        default: throw new ArgumentException("boardArea");
      }
    }
  }
}